<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all"/>
    <script src="/layuiadmin/layui/layui.js"></script>
</head>
<body style="background-color:#fff">

<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="" class="layui-form layui-form-pane" lay-filter="layui-form-pane" id="sbumitForm">
            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg6">
                    <label class="layui-form-label">等级名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="name"  placeholder="等级名称" lay-verify="required" autocomplete="off" class="layui-input" value=""/>
                    </div>
                </div>
            </div>

            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg6">
                    <label class="layui-form-label">等级序号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="rank_id"  placeholder="等级序号" lay-verify="required" autocomplete="off" class="layui-input" value=""/>
                    </div>
                </div>
            </div>

            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg6">
                    <label class="layui-form-label">价格：</label>
                    <div class="layui-input-block">
                        <input type="text" name="price"  placeholder="价格"  autocomplete="off" class="layui-input" value="" onkeyup="input_num(this)" />
                    </div>
                </div>
            </div>

            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg6">
                    <label class="layui-form-label">续费价格：</label>
                    <div class="layui-input-block">
                        <input type="text" name="renew_price"  placeholder="续费价格"  autocomplete="off" class="layui-input" value="" onkeyup="input_num(this)" />
                    </div>
                </div>
            </div>

            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg6">
                    <label class="layui-form-label">优惠：</label>
                    <div class="layui-input-block">
                        <select name="promo_id" lay-verify="required">
                            <option value="">请选择优惠</option>
                            {foreach $noble_promos as $v}
                            <option value="{$v.id}">开通奖励:{$v.reward} 续费奖励:{$v.renew_reward}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg6">
                    <label class="layui-form-label">礼物：</label>
                    <div class="layui-input-block">
                        <select name="gift_id" lay-verify="required">
                            <option value="">请选择礼物</option>
                            {foreach $gifts as $v}
                            <option value="{$v.id}">{$v.title}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg6">
                    <label class="layui-form-label">权重：</label>
                    <div class="layui-input-block">
                        <input type="text" name="weight"  placeholder="权重"  autocomplete="off" class="layui-input" value="" />
                    </div>
                </div>
            </div>

            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg6" style="float: left">
                    <label class="layui-form-label">VIP客服：</label>
                    <div class="layui-input-block" style="height: 35px;line-height: 35px">
                        <input type="checkbox" name="is_vip_service" lay-skin="switch" value="1" >
                    </div>
                </div>
            </div>

            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg6" style="float: left">
                    <label class="layui-form-label">防止禁言：</label>
                    <div class="layui-input-block" style="height: 35px;line-height: 35px">
                        <input type="checkbox" name="is_prevent_ban" lay-skin="switch" value="1" >
                    </div>
                </div>
            </div>

            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg6" style="float: left">
                    <label class="layui-form-label">贵宾席：</label>
                    <div class="layui-input-block" style="height: 35px;line-height: 35px">
                        <input type="checkbox" name="is_vip_seat" lay-skin="switch" value="1">
                    </div>
                </div>
            </div>

            <div class="layui-form-item" style="margin-top: 35px">
                <div class="layui-input-block">
                    <span class="layui-btn"  onclick="submitForm()" style="width: 100%">确认添加</span>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
    layui.use(['form'], function () {
        $ = layui.jquery;
        var form = layui.form, layer = layui.layer;
    });

    function submitForm() {
        layer.confirm('确认要添加吗？', {icon: 6}, function () {
            $.ajax({
                type: "POST", //请求方式
                url: '/admin/noble/level_add', //请求地址
                dataType: "json", //返回的数据类型
                data: $("#sbumitForm").serialize(), //数据
                //请求成功
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000}, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            window.parent.location.reload();
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 5000}, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }
                },
                //请求失败
                error: function (e) {
                    if (e.responseJSON.msg) {
                        layer.msg(e.responseJSON.msg, {icon: 2});
                    }
                }
            });
        });
    }

    function input_num(obj){
        obj.value = obj.value.replace(/[^\d.]/g,"");
        obj.value = obj.value.replace(/^\./g,"");
        obj.value = obj.value.replace(/\.{2,}/g,".");
        obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');

        if(obj.value.indexOf(".")> 0  && obj.value.indexOf("0")>2){
            obj.value= parseFloat(obj.value);
        }
        if(obj.value.indexOf(".")> 0  && obj.value.lastIndexOf("0")>2){
            obj.value= parseFloat(obj.value);
        }
        if (obj.value.indexOf(".") <= 0 && obj.value != "") {
            obj.value = parseFloat(obj.value);
        }
    }
</script>
</body>

</html>
